Tutorial 3 - Line following

Download the zip file here

Sensor : Ground sensors

To initialize the ground sensors:

gs = []
gsNames = ['gs0', 'gs1', 'gs2']
for i in range(3):
    gs.append(robot.getDevice(gsNames[i]))
    gs[i].enable(timestep)

To read the ground sensors inside the main loop:

gsValues = []
for i in range(3):
    gsValues.append(gs[i].getValue())

To read sensor values inside the main loop:

line_right = gsValues[0]
line_center = gsValues[1]
line_left = gsValues[2]

Complete the line following robot coding using using state-machine code

Pasted image 20250812102528.png

Exercise : Obstacle Avoidance

obstacle_avoidance.gif

How to add objects

  • "right click" on "RectangleArena"
  • "Add new"
  • Find "bottle"
  • Click on the arrow, to move the object
    Pasted image 20250812105131.png

Reference : Lima, J., & Martins, F. N. (n.d.). Lab 2 – Line-follower with State Machine. Robotics-Simulation-Labs. Retrieved August 12, 2025, from Felipe N. Martins GitHub Pages: https://felipenmartins.github.io/Robotics-Simulation-Labs/Lab2/